<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>rect</title>
</head>

<body>
    <canvas id="myCanvas" width="500" height="500">你的浏览器不支持canvas</canvas>

    <script>
        var canvas = document.getElementById('myCanvas')
        // 标识画布 获取上下文
        var ctx = canvas.getContext('2d')

        ctx.fillStyle = "blue"
        ctx.fillRect(0, 0, 200, 100) // fillRect(x, y, width, height) 绘制矩形(有填充) x,y 起始坐标(左上角) width height 矩形大小 单位px

        ctx.strokeStyle = 'red'
        ctx.strokeRect(0, 0, 100, 200) // 绘制矩形 无填充, 
    </script>
</body>

</html>